import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.getList(this);
			this.getQualityBox()
		},
		//获取下拉框数据
		getQualityBox(){
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/supplier/supplierQualityRecord/getQualityBox',
				data:{}
			}).then(res=>{
				let data=res.data
				if(data.status == 200){
					let result = data.result
					this.Model.filterOption.items.forEach(item=>{
						
						switch(item.key){
							case 'duty'://责任归属
								let dutysKeys=Object.keys(result.dutys)
								dutysKeys.forEach(key=>{
									item.data.push({
										label:result.dutys[key],
										value:key
									})
								})
							break;
							case 'status'://质检状态
								let statusKeys=Object.keys(result.qualityStatus)
								statusKeys.forEach(key=>{
									item.data.push({
										label:result.qualityStatus[key],
										value:key
									})
								})
							break;
							case 'qualityController'://质检人
								let qualityControllerKeys=Object.keys(result.qualityController)
								qualityControllerKeys.forEach(key=>{
									item.data.push({
										label:result.qualityController[key],
										value:key
									})
								})
							break;
						}
					})
				}
			})
		},
		//获取列表
		getList(that,params,pageIndex = 1,pageSize = 10) {
			// params = params || {businessType:131};
			params = params || {}
			var apiTest = this.apiTest;
			this.$ajax({
					method: 'post',
					url:apiTest+'/supplier/supplierQualityRecord/list',
					data:{
						condition:params,
						pageIndex: pageIndex,
						pageSize: pageSize,
					}
			    }).then((res)=>{
					that.Model.tableData = [];
					var data = res.data;
					if(data.status == 200){
						var pagination = commonObject.paginationFunction(data.result);
						that.Model.paginationObject = objDeepCopy(pagination);
						that.Model.tableData = data.result.result;
					}else{
			
					}
				});
		},
		//详情
		toDetial(row) {
			this.$router.push({
				path:'qualityBarcodeDetail',
				query:{
					barcode:row.barcode
				}
			});
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,val);
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			var params = this.Model.searchFromData;
			if(params){
				if(params.createTime&&params.createTime.length){
					params.createTimeStart=params.createTime[0]
					params.createTimeEnd=params.createTime[1]
					delete params.createTime
				}
				if(params.qualityTime&&params.qualityTime.length){
					params.qualityTimeStart=params.qualityTime[0]
					params.qualityTimeEnd=params.qualityTime[1]
					delete params.qualityTime
				}
			}
			this.getList(this,params);
		},
		toClear(val) {
			this.Model.searchFromData = {};
		},
		toExport(val) {
		  console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		objFilters:function(value){
			
		}
	}
}
export default Controller;
